﻿<!DOCTYPE html>
<!--设置排查标准-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
        <script src="/static/js/common.js"></script>

    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        /*穿梭框部分*/
        ._rowbox {
            position: relative;
            float: left;
            left: 50%;
            width: 100%;
        }

        ._rowbox ._box {
            padding: 5px;
            float: left;
            border: 1px solid #EBEEF5;
            width: 95%;
        }

        ._rowbox ._box ._sidebox {
            border: 1px solid #EBEEF5;
            padding: 5px;
            margin-top: 10px;
        }

        ._rowbox ._box ._middlebox {
            padding: 5px;
            margin-top: 10px;
            text-align: center;
        }

        ._rowbox ._box ._middlebox div {
            margin-bottom: 20px;
        }
    </style>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }
    </style>
</head>

<body style="overflow-x:hidden;">
    <div id="app" v-cloak class="popupW50">
        <el-form :model="Form" status-icon :rules="rules" ref="ruleForm" size="mini" label-position="right">
            <el-row>
                <el-col :span="11">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <el-input type="text" v-model="Form.Project" autocomplete="off" size="mini">
                                <template slot="prepend">
                                    {{RisksManagement.RiskContent.Project+mark.m}}
                                </template>
                            </el-input>
                        </el-form-item>
                    </div>
                </el-col>
                <el-col :span="11" offset="2">
                    <el-col>
                        <div class="elst-select-mini">
                            <el-form-item>
                                <el-input size="mini">
                                    <template slot="prepend">
                                        <div> {{RisksManagement.RiskContent.Region+mark.m}}</div>
                                    </template>
                                    <el-select @visible-change="visibleChange" v-model="Form.Region" slot="suffix"
                                        :placeholder="RisksManagement.RiskContent.Region">
                                        <el-option label="请选择" value=""></el-option>
                                        <el-option v-for="item in Region" :label="item.label" :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-input>
                            </el-form-item>
                        </div>
                    </el-col>
                </el-col>
                <el-col :span="24">
                    <div class="elst-select-mini">
                        <el-form-item>
                            <div class="el-input--mini el-input-group">
                                <div class="el-input-group__prepend">
                                    {{RisksManagement.RiskContent.Remark+mark.m}}
                                </div>
                                <el-input class="el-textarea__inner" type="textarea" v-model="Form.Remark"
                                    autocomplete="off"></el-input>
                            </div>
                        </el-form-item>
                    </div>
                </el-col>
            </el-row>
            <div class="_rowbox">
                <el-row style="margin-top:20px;left: -50%; ">
                    <div class="_box">
                        <div><span>{{RisksManagement.RiskContent.StandardChoice}}</span></div>
                        <el-col :span="9" class="_sidebox">
                            <div>
                                <el-col :span="24">
                                    <el-form-item :label="RisksManagement.RiskContent.UnSelected"> </el-form-item>
                                </el-col>
                            </div>
                            <div>
                                <el-col :span="24">
                                    <div class="elst-select-mini">
                                        <el-form-item>
                                            <el-input size="mini">
                                                <template slot="prepend">
                                                    {{RisksManagement.RiskCategory.Category+mark.m}}
                                                </template>
                                                <treeselect v-model="Form.UnType" :options="Type" :flat="true"
                                                    :show-count="true" :disable-branch-nodes="true" slot="suffix"
                                                    style="line-height: 28px;width: 74%;float: right;"
                                                    placeholder="请选择" />
                                            </el-input>
                                        </el-form-item>
                                    </div>
                                </el-col>
                            </div>
                            <div>
                                <el-col :span="16">
                                    <div class="elst-select-mini">
                                        <el-form-item>
                                            <el-input type="text" v-model="Form.UnSelectedStandard" autocomplete="off"
                                                size="mini">
                                                <template slot="prepend">
                                                    {{RisksManagement.RiskContent.Standard+mark.m}}
                                                </template>
                                            </el-input>
                                        </el-form-item>
                                    </div>
                                </el-col>
                                <el-col :span="7" offset="1">
                                    <el-button type="primary" @click="onSearch('left')" style="margin: 3px 0 0 10px;">
                                        {{col.btnSelect}}</el-button>
                                </el-col>
                            </div>
                            <el-table stripe :data="transferData" border ref="selectionLeft" height="300"
                                style="overflow:hidden;margin: 0 auto;" @selection-change="checkAll"
                                @select-all="selectLeftAll">
                                <el-table-column type="selection" align="center" width="40">
                                </el-table-column>
                                <!-- <el-table-column prop="type" :formatter="getDicValue"
                                    :label="RisksManagement.RiskCategory.Category">
                                </el-table-column> -->
                                <el-table-column prop="data" :label="RisksManagement.RiskContent.Standard">
                                </el-table-column>
                            </el-table>
                        </el-col>
                        <el-col :span="6" class="_middlebox">
                            <!-- <div>
                                <el-button type="primary" @click="UserInput('tj')">
                                    {{RisksManagement.RiskContent.InputContent}}
                                </el-button>
                            </div> -->
                            <div>
                                <el-button @click="handelSelect()" icon="el-icon-d-arrow-right"
                                    :disabled="nowSelectData.length?false:true" type="primary" style="width: 120px">
                                    {{RisksManagement.RiskContent.Selected}}
                                </el-button>
                            </div>
                            <div>
                                <el-button @click="handelSelectAll()" icon="el-icon-d-arrow-right" type="primary">
                                    {{RisksManagement.RiskContent.AllSelected}}
                                </el-button>
                            </div>
                            <div>
                                <el-button @click="handleRemoveSelect" icon="el-icon-d-arrow-left"
                                    :disabled="nowSelectRightData.length?false:true" type="primary">
                                    {{RisksManagement.RiskContent.Cancel}}
                                </el-button>
                            </div>
                            <div>
                                <el-button @click="handleRemoveSelectAll" icon="el-icon-d-arrow-left" type="primary">
                                    {{RisksManagement.RiskContent.AllCancel}}
                                </el-button>
                            </div>
                        </el-col>
                        <el-col :span="9" class="_sidebox">
                            <el-row>
                                <el-col :span="24">
                                    <el-form-item :label="RisksManagement.RiskContent.OnSelected"> </el-form-item>
                                </el-col>
                            </el-row>
                            <el-row>
                                <el-col :span="24">
                                    <div class="elst-select-mini">
                                        <el-form-item>
                                            <el-input size="mini">
                                                <template slot="prepend">
                                                    {{RisksManagement.RiskCategory.Category+mark.m}}
                                                </template>
                                                <treeselect v-model="Form.OnType" :options="Type" :flat="true"
                                                    :show-count="true" :disable-branch-nodes="true" slot="suffix"
                                                    style="line-height: 28px;width: 74%;float: right;"
                                                    placeholder="请选择" />
                                            </el-input>
                                        </el-form-item>
                                    </div>
                                </el-col>
                            </el-row>
                            <el-row>

                                <el-col :span="16">
                                    <div class="elst-select-mini">
                                        <el-form-item>
                                            <el-input type="text" v-model="Form.OnSelectedStandard" autocomplete="off"
                                                size="mini">
                                                <template slot="prepend">
                                                    {{RisksManagement.RiskContent.Standard+mark.m}}
                                                </template>
                                            </el-input>
                                        </el-form-item>
                                    </div>
                                </el-col>
                                <el-col :span="7" offset="1">
                                    <el-button type="primary" @click="onSearch('right')" style="margin: 3px 0 0 10px;">
                                        {{col.btnSelect}}</el-button>
                                </el-col>
                            </el-row>
                            <el-table stripe :data="selectArr" border ref="selectionRight" height="300"
                                style="overflow:hidden;margin: 0 auto;" @selection-change="checkRightAll"
                                @select-all="selectRightAll">
                                <el-table-column type="selection">
                                </el-table-column>
                                <!-- <el-table-column prop="type" :formatter="getDicValue"
                                    :label="RisksManagement.RiskCategory.Category">
                                </el-table-column> -->
                                <el-table-column prop="data" :label="RisksManagement.RiskContent.Standard">
                                </el-table-column>


                            </el-table>
                        </el-col>
                    </div>
                </el-row>
            </div>
            <el-row type="flex" justify="end" style="float:right;width:100%;">
                <el-form-item>
                    <br>
                    <el-button type="primary" @click="onSubmitForm('ruleForm')">{{col.btnSubmit}}</el-button>
                    <el-button type="primary" @click="parent.ListItem.dialogVisible=false">{{col.btnBack}}</el-button>
                    <br>
                    <br>
                </el-form-item>
            </el-row>

        </el-form>
        <el-dialog title="录入隐患排查标准" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%" height="80%"
            top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        $(function () {
            //同步按钮大小
            var $btns = $("._middlebox button");
            $btns.width($btns.eq(0).width())
            $("._middlebox").height($("._sidebox").height() + 2);
        })
        Vue.component('treeselect', VueTreeselect.Treeselect)
        app = new Vue({
            el: '#app',
            data: {
                //父页传参
                id: '',
                pid: '',
                ListItem: ListItem,
                mydata: myTree,
                RiskType: RiskType,
                api: '',
                //业务表单内容
                Form: {
                    id: '',
                    pid: '',
                    Project: '',
                    Region: '',
                    Remark: '',
                    Standard: [],
                    //筛选
                    UnType: null,//待选择排查类别
                    UnSelectedStandard: '',//待选择排查标准
                    OnType: null,//已选择排查类别
                    OnSelectedStandard: '',//已选择排查标准
                },
                Region: [],//涉及区域
                Type: [],//排查类别
                //表单验证
                rules: {

                },
                transferData: [],//穿梭框初始化内容
                selectArr: [],  // 已选中
                nowSelectData: [], // 待选择框中选中的部分
                nowSelectRightData: [], // 已选择框中选中的部分
                tempLeft: [],
                tempRight: [],
                childrenAdd: {},
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                getDicValue: function (row, column, cellValue, index) {
                    return getTreeValue(this.RiskType, cellValue)
                },
                //Dialog展示
                UserInput: function (val, id) {
                    //DialogShow(this, val, "RiskContentEditStandardTypeInput.html", id);
                    var url = "RiskContentEditStandardTypeInput.html";
                    this.ListItem.InputUrl = url + "?id=" + this.id + "&pid=" + this.pid + "&api=" + this.api + "&t=" + Date.parse(new Date());
                    this.ListItem.dialogVisible = true;
                },
                closeDialog: function () {

                    this.getData();

                    //此处应补一个添加的内容数组对象

                    this.Form.Standard.unshift(this.childrenAdd)//获取子页面新添加的对象

                    this.selectArr = [];
                    this.selectArr = this.handleConcatArr(this.selectArr, this.Form.Standard)//合并数据到穿梭框

                },
                //提交数据
                onSubmitForm: function (formName) {
                    var mythis = this;
                    mythis.Form.pid = mythis.pid;
                    mythis.$refs[formName].validate(function (valid) {
                        //验证通过
                        if (valid) {
                            var parentForm = parent.app.Form;
                            var myList = mythis.Form.Standard;
                            console.log('A', parentForm.InputTable);
                            console.log('B', myList)
                            // return false;
                            //修改
                            if (mythis.id) {
                                var InputTableIndex = [];
                                for (var j = 0; j < parentForm.InputTable.length; j++) {
                                    if (parentForm.InputTable[j].id == mythis.id) {
                                        InputTableIndex.push(j);
                                    }
                                }
                                for (var k = InputTableIndex.length - 1; k >= 0; k--) {
                                    parentForm.InputTable.splice(InputTableIndex[k], 1);
                                }
                                for (var l = mythis.Form.Standard.length - 1; l >= 0; l--) {
                                    var data = {
                                        id: mythis.id,
                                        Project: '',

                                        AddClass: '知识库',//添加类别
                                        Project: mythis.Form.Project,//排查项目
                                        Region: mythis.Form.Region,//涉及区域
                                        Remark: mythis.Form.Remark,//备注说明
                                        Standard: mythis.Form.Standard[l],//排查标准
                                        RiskLevel: mythis.Form.RiskLevel
                                    }
                                    parentForm.InputTable.splice(InputTableIndex[0], 0, data);
                                }

                            }
                            else {
                                //新增
                                var id = Mock.Random.id();

                                for (var j = mythis.Form.Standard.length - 1; j >= 0; j--) {
                                    parentForm.InputTable.unshift({
                                        id: id,
                                        AddClass: '知识库',//添加类别
                                        Region: mythis.Form.Region,//涉及区域
                                        Remark: mythis.Form.Remark,//备注说明
                                        Standard: mythis.Form.Standard[j],//排查标准
                                        RiskLevel: randomKey("03"),//隐患级别
                                        Project: mythis.Form.Project,//排查项目
                                        Region: mythis.Form.Region,//涉及区域
                                        Remark: mythis.Form.Remark,//备注说明
                                        Standard: mythis.Form.Standard[j],//排查标准
                                        RiskLevel: randomKey("03"),//隐患级别
                                        Result: '完成',//隐患级别
                                    })
                                }
                            }




                            parent.app.ListItem.dialogVisible = false;

                        } else {
                            //验证失败
                            return false;
                        }
                    });
                },
                //读取数据
                getData: function () {
                    var mythis = this;
                    var parentForm = parent.app.Form;
                    var myuser = [];
                    // if (parentForm.InputTable.length) {
                    //     parentForm.InputTable.forEach(function (v, i) {
                    //         if (v.id == mythis.id) {
                    //             myuser.push(v);
                    //         }
                    //     })
                    // }
                    var _myuser = {};
                    if (myuser.length) {
                        myuser.forEach(function (v, i) {
                            if (i == 0) {
                                for (var key in v) {
                                    _myuser[key] = v[key];
                                }
                                _myuser.Standard = [];
                                _myuser.Standard.push(v.Standard);
                            }
                            else {
                                _myuser.Standard.push(v.Standard);
                            }
                        })
                    }
                    $.extend(true, mythis.Form, _myuser)
                },
                //以下是穿梭框相关方法
                //初始化穿梭框数据
                generateData: function () {
                    const data = [];
                    for (var i = 1; i <= 15; i++) {
                        data.push(Mock.mock({
                            name: i,
                            data: '排查标准' + i,
                            type: '6'
                        }));
                    }
                    return data;
                },
                //待选择-选中所有
                checkAll: function (val) {
                    this.nowSelectData = val;
                },
                //已选择-选中所有
                checkRightAll: function (val) {
                    this.nowSelectRightData = val;
                },
                // 选中
                handelSelect: function () {
                    //更新实际数据
                    this.selectArr = this.handleConcatArr(this.selectArr, this.nowSelectData)
                    this.handleRemoveTabList(this.nowSelectData, this.transferData);
                    //更新查询用临时数据
                    if (this.tempRight) this.tempRight = this.handleConcatArr(this.tempRight, this.nowSelectData)
                    if (this.tempLeft) this.handleRemoveTabList(this.nowSelectData, this.tempLeft);
                    //更新传值
                    //this.handleRemoveTabList(this.nowSelectRightData, this.Form.Standard);
                    this.Form.Standard = this.handleConcatArr(this.Form.Standard, this.nowSelectData)
                    //清空选择集合
                    this.nowSelectData = [];
                },
                // 取消
                handleRemoveSelect: function () {
                    //更新实际数据
                    this.transferData = this.handleConcatArr(this.transferData, this.nowSelectRightData)
                    this.handleRemoveTabList(this.nowSelectRightData, this.selectArr);
                    //更新查询用临时数据
                    if (this.tempLeft) this.tempLeft = this.handleConcatArr(this.tempLeft, this.nowSelectRightData)
                    if (this.tempRight) this.handleRemoveTabList(this.nowSelectRightData, this.tempRight);
                    //更新传值
                    //this.Form.Standard = this.handleConcatArr(this.Form.Standard, this.nowSelectData)
                    this.handleRemoveTabList(this.nowSelectRightData, this.Form.Standard);
                    //清空选择集合
                    this.nowSelectRightData = [];
                },
                // 选中全部
                handelSelectAll: function () {
                    this.$refs.selectionLeft.toggleAllSelection();
                },
                // 取消全部
                handleRemoveSelectAll: function () {
                    this.$refs.selectionRight.toggleAllSelection();
                },
                //合并数组
                handleConcatArr: function (selectArr, nowSelectData) {
                    var arr = [];
                    arr = arr.concat(selectArr, nowSelectData);
                    return arr;
                },
                //拆分数组
                handleRemoveTabList: function (isNeedArr, originalArr) {
                    if (isNeedArr.length && originalArr.length) {
                        for (var i = 0; i < isNeedArr.length; i++) {
                            for (var k = 0; k < originalArr.length; k++) {
                                if (isNeedArr[i]["name"] + '' === originalArr[k]["name"] + '') {
                                    originalArr.splice(k, 1);
                                }
                            }
                        }
                    }
                },
                //>>全部选择
                selectLeftAll: function (selection) {
                    this.handelSelect();
                },
                //<<全部撤销
                selectRightAll: function (selection) {
                    this.handleRemoveSelect();
                },
                //穿梭框筛选按钮
                onSearch: function (type) {
                    if (type === 'left') {
                        if (this.tempLeft.length > 0)
                            this.transferData = this.tempLeft;
                        else
                            this.tempLeft = this.transferData;
                        var leftArr = this.transferData;
                        var newArr = [];
                        for (var i = 0; i < leftArr.length; i++) {
                            var user = leftArr[i];
                            if (this.Form.UnType && user.type.indexOf(this.Form.UnType) == -1)
                                continue;
                            if (this.Form.UnSelectedStandard && user.data.indexOf(this.Form.UnSelectedStandard) == -1)
                                continue;
                            newArr.push(leftArr[i]);
                        }
                        this.transferData = newArr;
                    }
                    else if (type === 'right') {
                        if (this.tempRight.length > 0)
                            this.selectArr = this.tempRight;
                        else
                            this.tempRight = this.selectArr;
                        var rightArr = this.selectArr;
                        var newArr = [];
                        for (var i = 0; i < rightArr.length; i++) {
                            var user = rightArr[i];
                            if (this.Form.OnType && user.type.indexOf(this.Form.OnType) == -1)
                                continue;
                            if (this.Form.OnSelectedStandard && user.data.indexOf(this.Form.OnSelectedStandard) == -1)
                                continue;
                            newArr.push(rightArr[i]);
                        }
                        this.selectArr = newArr;
                    }

                }
            },
            mounted: function () {
                this.Region = fn(this.mydata, "0");
                this.Region.forEach(function (v, i) {
                    v.id += '';
                })
                this.Type = fn(this.RiskType, "0");
                //穿梭框左边可选数据内容初始化(模拟15条测试数据，之后需删除)
                this.transferData = this.generateData();
                this.id = getUrlParam("id");
                this.pid = getUrlParam("pid");
                this.api = getUrlParam("api");
                this.getData();
                //将父页传过来的数据赋值给当前选中数据
                //this.nowSelectData = this.Form.Standard;
                //初始化穿梭框选中状态

                this.selectArr = this.handleConcatArr(this.selectArr, this.Form.Standard)
                this.handleRemoveTabList(this.Form.Standard, this.transferData);


                ////将父页传过来的数据赋值给当前选中数据
                //this.nowSelectData = this.Form.Standard;
                ////初始化穿梭框选中状态
                //this.selectArr = this.handleConcatArr(this.selectArr, this.nowSelectData)
                //this.handleRemoveTabList(this.nowSelectData, this.transferData);
                ////初始化完成后，清空当前选中数据
                //this.nowSelectData = [];
            }
        });
    </script>

</body>

</html>